package cn.wsalix.order.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import cn.anlaser.entity.BasicEntity;
import cn.wsalix.status.TuanEnum;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "MASTER_TUAN")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(exclude={"tuanOrders"},callSuper = false)
@ToString(exclude = { "tuanOrders" })
public class MasterTuan extends BasicEntity {
	@Id
	private Long id;
	/**
	 * name：团主名字
	 */
	private static final long serialVersionUID = 7245697631565191281L;
	private Long productId;
	private String tradeNo;// 订单号
	private String shareUrl;// 分享URL
	private String shareTitle;// 分享标题
	private String shareContent;// 分享标题
	private String customerName;//团长名字
	private String avatar;//团长头像
	@Temporal(TemporalType.TIMESTAMP)
	private Date beginTime;
	@Temporal(TemporalType.TIMESTAMP)
	private Date endTime;//yyyy-MM-dd HH:mm:ss
	//private String orderDate;// 开团时间
	
	private TuanEnum tuanStatus;
	private int tuanNum;	
	private int currNum;
	private long amount;

	@JsonIgnore
	@OneToOne(optional = false, cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
	@MapsId
	@JoinColumn(name = "ID")
	private Order masterOrder;
	
/*	@JsonIgnore
	@OneToOne(optional = false, cascade = CascadeType.MERGE)
	@JoinColumn(name = "MASTER_ORDER_ID", referencedColumnName = "ID", unique = true)
	private Order masterOrder;*/// 支付账号
	@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY, mappedBy = "masterTuan")
	private List<Order> tuanOrders;	

/*	@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY, mappedBy = "masterTuan")
	private Set<OrderInfo> orderInfos;	*/
	/*@JsonIgnore
	@OneToOne(optional = false, cascade = CascadeType.MERGE)
	@JoinColumn(name = "ORDER_ID", referencedColumnName = "ID", unique = true)
	private Order order;*/
	
/*	@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY, mappedBy = "tuanMaster")
	private Set<Order> tuanOrders;	
	
	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(name = "MASTER_ID")
	private SysUser master;*/
}